package subject_set.offer100;

/**
 * @author haomin
 * @date 2022/10/25 16:14
 **/
public class Offer58 {
    class Solution {
        public String reverseWords(String s) {
            s = s.trim();
            String[] arr = s.split(" ");
            StringBuffer sb = new StringBuffer();
            for(int i = 0; i < arr.length; ++i){
                if(arr[i].length() == 0) continue;
                if(i != arr.length-1){
                    sb.append(new StringBuffer(arr[i]).reverse()).append(" ");
                }else sb.append(new StringBuffer(arr[i]).reverse());
            }
            return sb.reverse().toString();
        }
    }
}